﻿using System.Windows;
using System.Windows.Controls;
using BrainTechLLC;
using ImageAppViewModels;

namespace WpfImageDuplicates
{
    /// <summary>
    /// Interaction logic for RecordedEventInfoView.xaml
    /// </summary>
    public partial class RecordedEventInfoView : UserControl
    {
        public RecordedEventInfoView()
        {
            InitializeComponent();
        }

        public static readonly DependencyProperty RecordedEventInfoViewModelProperty =
            DependencyProperty.Register("RecordedEventInfoViewModel", typeof(RecordedEventInfoViewModel), typeof(RecordedEventInfoView), new PropertyMetadata(null, OnRecordedEventInfoViewModelPropertyChanged));

        public RecordedEventInfoViewModel RecordedEventInfoViewModel
        {
            get { return (RecordedEventInfoViewModel)GetValue(RecordedEventInfoViewModelProperty); }
            set { SetValue(RecordedEventInfoViewModelProperty, value); }
        }

        private static void OnRecordedEventInfoViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RecordedEventInfoView source = d as RecordedEventInfoView;
            source.UpdateRecordedEventInfoViewModel(e.NewValue as RecordedEventInfoViewModel, e.OldValue as RecordedEventInfoViewModel);
        }

        public void UpdateRecordedEventInfoViewModel(RecordedEventInfoViewModel viewModel, RecordedEventInfoViewModel viewModelOld)
        {
            RecordedEventInfoViewModel = viewModel;
            this.DataContext = RecordedEventInfoViewModel;
        }

        private void Refresh_Click(object sender, RoutedEventArgs e)
        {
            RecordedEventInfoViewModel.ReconcileListDifferences(RecordedEventInfo.Instance.EventInfos.AllItems);
        }
    }
}
